Skip to content

fix(plan): prevent subagent plan escape, show plan in exit prompt, render as markdown#18516

Open
BYK wants to merge 5 commits intoanomalyco:devfrom
BYK:fix/plan-mode-subagent-escape
Open

fix(plan): prevent subagent plan escape, show plan in exit prompt, render as markdown#18516
BYK wants to merge 5 commits intoanomalyco:devfrom
BYK:fix/plan-mode-subagent-escape

Conversation

@BYK
Copy link
Copy Markdown
Contributor

@BYK BYK commented Mar 21, 2026

Issue for this PR

Closes #18515

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes three issues with the experimental planning mode and adds UX improvements to the question dock:

1. Subagents can escape plan mode — When the plan agent spawns explore/general subagents via the task tool, those child sessions had access to plan_exit. If a subagent called it and the user accidentally confirmed, the session would switch to build mode prematurely. Fix: deny plan_exit and plan_enter both in subagent session creation permissions (Session.create()) AND in the tools map passed to SessionPrompt.prompt(). The latter is critical because SessionPrompt.prompt() overwrites session permissions with its tools parameter — without plan_exit: false in the tools map, the deny rule from session creation was silently lost.

2. Plan not shown before build switchplan_exit asked "Would you like to switch?" without showing what the plan actually says. The user had to go read the plan file separately. Fix: read the plan file content via Bun.file() in PlanExitTool and append it to the question text below a horizontal rule. If the plan file is empty/missing, return an error telling the agent to write the plan first instead of showing an empty question.

3. Question text renders as plain text — The question dock rendered question.question as raw text, not markdown. Even with the plan content included, headers/lists/code blocks would display unformatted. Fix: use the Markdown component in both the live question dock (session-question-dock.tsx) and historical message display (message-part.tsx). Added overflow-y: auto; max-height: 40vh to the question-text CSS so long plans scroll within the dock.

4. Question dock can now be minimized — Added a minimize/expand toggle to the question dock so users can collapse it to read the conversation while a question is pending. The DockPrompt component gains a minimized prop that hides content and footer. The header title is clickable (with flex: 1 to fill the row) and a chevron button toggles the state, matching the existing todo dock collapse pattern.

5. Question dock text is now selectable — Added [data-slot="question-text"] to the user-select: text allow-list in message-part.css so plan content is selectable and copyable.

How did you verify your code works?

  • Tools map now includes plan_exit: false and plan_enter: false which survives the SessionPrompt.prompt() permission overwrite
  • Empty plan guard returns error before showing question to user
  • Markdown component renders question text with proper formatting
  • Question dock minimize toggle follows todo dock pattern; title fills header row via flex: 1 for large click target
  • [data-slot="question-text"] in user-select: text allow-list enables copy
  • Built and tested locally

Screenshots / recordings

N/A — planning mode is experimental and behind a flag. The markdown rendering, minimize, and text selection changes apply to all question docks.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@BYK BYK requested a review from adamdotdevin as a code owner March 21, 2026 11:50
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

BYK added 3 commits March 25, 2026 10:45
…nder as markdown

Three fixes for experimental planning mode:

1. Deny plan_exit/plan_enter permissions on subagent sessions so
   explore/general agents spawned by the plan agent cannot accidentally
   trigger a mode switch to build.

2. Read the plan file content in PlanExitTool and embed it in the
   question text so users see the full plan before deciding to switch.

3. Render question text with the Markdown component instead of raw
   text, both in the live question dock and historical message parts.
   Add overflow-y/max-height to question-text CSS so long plans scroll
   within the dock.
… minimize

Two additional fixes:

1. Add plan_exit/plan_enter to the tools disable map in task.ts.
   The session permissions were being overwritten by SessionPrompt.prompt()
   which converts the tools map into session permissions. Without plan_exit
   in the tools map, it wasn't being denied.

2. Add minimize/expand toggle to the question dock so users can collapse
   it to read the conversation while a question is pending. Adds a
   chevron button in the header and makes the title clickable to toggle.
   DockPrompt gains a minimized prop that hides content and footer.
@BYK BYK force-pushed the fix/plan-mode-subagent-escape branch 2 times, most recently from 317481c to a42c629 Compare March 26, 2026 12:28
…selection

1. Restore Markdown component usage in live question dock — the
   rebase dropped it, leaving plain text rendering while the import
   was still present.

2. Refuse plan_exit when plan file is empty/missing — return an error
   telling the agent to write the plan first instead of showing an
   empty question to the user.

3. Add question-text to the user-select: text allow-list so plan
   content in the question dock is selectable and copyable.
@BYK BYK force-pushed the fix/plan-mode-subagent-escape branch from a42c629 to 2a0d4cc Compare March 26, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Planning mode: subagents can trigger plan_exit, plan not shown before build switch, question text renders as plain text

1 participant